﻿using Autofac;

namespace ASPApiDemo.Extension
{
    public class AutofacPropertityModule : Module
    {
        // 如果想在controller除了构造函数注入之外，启用属性注入
        // 需要将controller注入容器并且指定PropertiesAutowired
        protected override void Load(ContainerBuilder builder)
        {
            //base.Load(builder);
            var controllerBaseType = typeof(Microsoft.AspNetCore.Mvc.ControllerBase);
            //注册controller
            builder.RegisterAssemblyTypes(typeof(Program).Assembly)
                .Where(t => controllerBaseType.IsAssignableFrom(t))
                .PropertiesAutowired();
        }
    }
}
